import {
  imageUrl
} from "../../utils/imageutil"
let app = getApp()
Page({
  data: {
    imageUrl,
    shows: false,
    user_nickname: '',
    id_number: '',
    type: 1,
    titleBarHeight: app.globalData.titleBarHeight,
    titleBarUsableWidth: app.globalData.titleBarUsableWidth,
    addrtype_arr:[{title:'身份证',type:1},{title:'港澳台居民往来内地通行证',type:2}],
    addrtype_value:0,
  },
  show() {
    var that = this;
    var sh = that.data.shows;
    that.setData({
      shows: !sh
    })
  },
  onLoad: function (options) {
    if (options.type) {
      this.setData({
        type: options.type
      })
    }
    wx.setNavigationBarColor({
      backgroundColor: '#ffffff',
      frontColor: '#ffffff',
    })
  },
  changeuser_nickname(e) {
    this.setData({
      user_nickname: e.detail.value
    })
  },
  changeid_number(e) {
    this.setData({
      id_number: e.detail.value
    })
  },
  change_addrtype(e){
    this.setData({
      addrtype_value:e.detail.value
    })
  },
  getAuthentication() {
    if (this.data.user_nickname == '') {
      wx.showToast({
        title: '请输入您的真实姓名',
        icon: 'none'
      })
      return false
    }
    if (this.data.id_number == '') {
      wx.showToast({
        title: '请输入您的证件号码',
        icon: 'none'
      })
      return false
    }
    let data = {};
    if (this.data.type == 1) {
      data = {
        uid: wx.getStorageSync('userInfo').id,
        type: this.data.type
      }
    } else {
      data = {
        uid: wx.getStorageSync('auntInfo').id,
      }
    }
    getApp().globalData.post({
      data: {
        do: 'Authentication',
        user_nickname: this.data.user_nickname,
        id_number: this.data.id_number,
        addrtype:this.data.addrtype_arr[this.data.addrtype_value].type,
        ...data
      }
    }).then(res => {
      getApp().showModal(res.data.msg).then(() => {
        if (res.data.code == 1) {
          if (this.data.type == 1) {
            let userInfo = wx.getStorageSync('userInfo');
            userInfo.real_name = this.data.user_nickname;
            userInfo.id_number = this.data.id_number;
            wx.setStorageSync('userInfo', userInfo)
          } else {
            let auntInfo = wx.getStorageSync('auntInfo');
            auntInfo.user_nickname = this.data.user_nickname;
            auntInfo.id_number = this.data.id_number;
            wx.setStorageSync('auntInfo', auntInfo)
          }
          this.to_back()
        }
      })

    })
  },
  to_back() {
    wx.navigateBack({
      delta: 1
    })
  },
})